let utils = data["utils"];
let STUtil = data["STUtil"];
let Node = data["Node"];
let SplayTree = data["SplayTree"];
console.log("04Splaytree01");
utils.extend(SplayTree.prototype, {
  at: function (index) {
    for (var current = this._root, done = !1, i = 0, Q = []; !done;)
      if (current) Q.push(current), current = current.left;
      else if (Q.length > 0) {
        if (current = Q.pop(), i === index) return current;
        i++ , current = current.right
      } else done = !0;
    return null
  },
  next: function (d) {
    var root = this._root,
      successor = null;
    if (d.right) {
      for (successor = d.right; successor.left;) successor = successor.left;
      return successor
    }
    for (var comparator = this._comparator; root;) {
      var cmp = comparator(d.key, root.key);
      if (0 === cmp) break;
      cmp < 0 ? (successor = root, root = root.left) : root = root.right
    }
    return successor
  },
  prev: function (d) {
    var root = this._root,
      predecessor = null;
    if (null !== d.left) {
      for (predecessor = d.left; predecessor.right;) predecessor = predecessor.right;
      return predecessor
    }
    for (var comparator = this._comparator; root;) {
      var cmp = comparator(d.key, root.key);
      if (0 === cmp) break;
      cmp < 0 ? root = root.left : (predecessor = root, root = root.right)
    }
    return predecessor
  },
  clear: function () {
    return this._root = null, this._size = 0, this
  },
  toList: function () {
    return STUtil.toList(this._root)
  },
  load: function (keys, values, presort) {
    void 0 === values && (values = []), void 0 === presort && (presort = !1);
    var size = keys.length,
      comparator = this._comparator;
    if (presort && STUtil.sort(keys, values, 0, size - 1, comparator), null === this._root) this._root = STUtil.loadRecursive(keys, values, 0, size), this._size = size;
    else {
      var mergedList = STUtil.mergeLists(this.toList(), STUtil.createList(keys, values), comparator);
      size = this._size + size, this._root = STUtil.sortedListToBST({
        head: mergedList
      }, 0, size)
    }
    return this
  },
  isEmpty: function () {
    return null === this._root
  },
  toString: function (printNode) {
    void 0 === printNode && (printNode = function (n) {
      return String(n.key)
    });
    var out = [];
    return STUtil.printRow(this._root, "", !0, (function (v) {
      return out.push(v)
    }), printNode), out.join("")
  },
  update: function (key, newKey, newData) {
    var comparator = this._comparator,
      _a = STUtil.split(key, this._root, comparator),
      left = _a.left,
      right = _a.right;
    comparator(key, newKey) < 0 ? right = STUtil.insert(newKey, newData, right, comparator) : left = STUtil.insert(newKey, newData, left, comparator), this._root = STUtil.merge(left, right, comparator)
  },
  split: function (key) {
    return STUtil.split(key, this._root, this._comparator)
  }
})

return {
  "utils": utils,
  "STUtil": STUtil,
  "Node": Node,
  "SplayTree": SplayTree
}